package com.dada.controller.admin;

import com.alibaba.fastjson.JSON;
import com.dada.domain.admin.AdminInfo;
import com.dada.domain.common.ApiConstants;
import com.dada.domain.common.Code;
import com.dada.domain.common.JsonResult;
import com.dada.domain.common.Path;
import com.dada.domain.exception.ApiException;
import com.dada.domain.vos.User;
import com.dada.service.admin.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

import static com.dada.domain.common.ApiConstants.APPLICATION_JSON;
import static org.springframework.web.bind.annotation.RequestMethod.GET;

/**
 * Created by jianweilin on 16/9/5.
 */
@Slf4j
//@Validated
@RestController
@RequestMapping(produces = APPLICATION_JSON)
public class AdminController implements Path,ApiConstants{
    @Autowired
    private AdminService adminService;

    @RequestMapping(value = FIND_ADMINS,method = GET)
    JsonResult<List<AdminInfo>> list(@NotNull @RequestParam Integer id){
        if(false) {
            List<AdminInfo> admins = adminService.findById(id);
            log.info("adminInfo ==> " + JSON.toJSONString(admins));
            log.info("jsonResult" + JsonResult.ok(admins.get(0)));
            return JsonResult.ok(admins);
        } else {
            throw new ApiException(Code.SERVER_ERROR);
        }
    }

    @RequestMapping(value = "/userInfo",method = RequestMethod.POST)
    public JsonResult get(@RequestBody @Valid User user){
        log.info("user ==> " + JSON.toJSONString(user));
        return JsonResult.ok();
    }
}
